<%@page import="java.sql.*"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询结果</title>
<style type="text/css">
h1{ color: red;}
</style>
</head>
<body>
<% 
String first=request.getParameter("firstWord");
String url="jdbc:mysql://localhost:3306/db?serverTimezone=PRC";
//(1)加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//(2)创建连接
Connection cn = DriverManager.getConnection(url,"root","12qwas");
//(3)创建sql插入语句并设定参数的值
PreparedStatement ps = cn.prepareStatement("select cy from chengyu where first=?");
ps.setString(1, first);
%>
<h1>根据首字搜索成语结果如下</h1>
<p>以【<%=first%>】开头的成语有：</p>
<%
ResultSet rs = ps.executeQuery();
out.print(" / ");
while(rs.next()){
	String szcx=rs.getString("cy");
	out.print(szcx+" / ");
}
rs.close();
ps.close();
cn.close();
%>
</body>
</html>